<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增条形码')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-tag-add">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">codeid：</label>
            <div class="col-sm-8">
                <input name="codeid" id="codeid" class="form-control" type="text" required>
            </div>
            <span id="codePrompt" class="form-control" style="border: 0px;">
                <i class="fa fa-mail-forward border-box"></i>
                <i></i>
            </span>
        </div>

        <!-- WM(Waiting  modify)：修改为树装选择图-->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">暂存点：</label>
            <div class="col-sm-8">
                <select name="stagingId" id="stagingId" class="form-control m-b"
                        th:with="type=${@dep.depts(null,'400,310,360,370')}"
                        required>
                    <option value="">请选择</option>
                    <option th:each="dep : ${type}" th:text="${dep.deptName}" th:value="${dep.deptId}"></option>
                </select>
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">录入类型：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<div class="radio check-box">-->
                    <!--<label>-->
                        <!--<input type="radio" value="18" class="selling_cards" checked=""> <i></i> 逐条</label>-->
                <!--</div>-->
                <!--<div class="radio check-box">-->
                    <!--<label>-->
                        <!--<input type="radio" value="20" class="selling_cards"> <i></i> 批量</label>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">采集用户：</label>
            <div class="col-sm-8">
                <select name="collectUserId" id="collectUserId" class="form-control m-b" disabled="disabled">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">来源垃圾桶：</label>
            <div class="col-sm-8">
                <select name="sourceBucketId" id="sourceBucketId" class="form-control m-b" disabled="disabled">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">采集扫码时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="collectScanDate" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text"
                           required>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">来源科室：</label>
            <div class="col-sm-8">
                <select name="sourceDeptId" id="sourceDeptId" class="form-control m-b" disabled="disabled">
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">来源科室时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="scanDeptDate" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text"
                           required>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">医废类别：</label>
            <div class="col-sm-8">
                <select name="trashType" class="form-control m-b" th:with="type=${@dict.getType('yf_trash_type')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">重量输入方式：</label>
            <div class="col-sm-8">
                <select name="weightInputType" class="form-control m-b"
                        th:with="type=${@dict.getType('yf_weight_type')}" disabled="disabled" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">重量(kg)：</label>
            <div class="col-sm-8">
                <input name="weight" class="form-control" type="number" required>
            </div>
        </div>
        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label is-required">数量：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<input name="bag" class="form-control" type="number" required max="100" min="1">-->
            <!--</div>-->
        <!--</div>-->

        <div class="form-group">
            <label class="col-sm-3 control-label">照片地址：</label>
            <div class="col-sm-8">
                <input name="img" class="form-control" type="file">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">采集上传时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="collectUpdateDate" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text"
                           required>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">入库用户：</label>
            <div class="col-sm-8">
                <select name="intoUserId" id="intoUserId" class="form-control m-b" disabled="disabled" required>
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">入库垃圾桶：</label>
            <div class="col-sm-8">
                <select name="intoBucketId" id="intoBucketId" class="form-control m-b" disabled="disabled">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">入库时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="intoDate" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出库用户：</label>
            <div class="col-sm-8">
                <select name="outUserId" id="outUserId" class="form-control m-b" disabled="disabled" required>
                    <option value="0">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出库垃圾桶：</label>
            <div class="col-sm-8">
                <select name="outBucketId" id="outBucketId" class="form-control m-b" disabled="disabled">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">出库时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="outDate" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                </div>
            </div>
        </div>

        <!-- 动态 -->
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">医废出入库状态 ：</label>
            <div class="col-sm-8">
                <select name="trashStatus" class="form-control m-b" th:with="type=${@dict.getType('yf_trash_status')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出库运输车辆id：</label>
            <div class="col-sm-8">
                <input name="outCarId" class="form-control" type="text">
            </div>
        </div>


        <!-- 动态 -->
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <select name="status" class="form-control m-b" th:with="type=${@dict.getType('yf_exception_status')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>

        <!--设备表-->
        <div class="form-group">
            <label class="col-sm-3 control-label">采集设备 id：</label>
            <div class="col-sm-8">
                <input name="collectId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">入库设备 id：</label>
            <div class="col-sm-8">
                <input name="intoId" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出库设备 id：</label>
            <div class="col-sm-8">
                <input name="outId" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">采集设备信息：</label>
            <div class="col-sm-8">
                <input name="collectDetails" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">入库设备信息：</label>
            <div class="col-sm-8">
                <input name="intoDetails" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出库设备信息：</label>
            <div class="col-sm-8">
                <input name="outDetails" class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">删除状态：</label>
            <div class="col-sm-8">
                <select name="delFlag" class="form-control m-b" th:with="type=${@dict.getType('del_flag')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">更新方式：</label>
            <div class="col-sm-8">
                <select name="updateWay" class="form-control m-b" th:with="type=${@dict.getType('yf_update_way')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:selected="${dict.isDefault=='Y'}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    var prefix = ctx + "yf/tag"
    var codeB = null; //验证通过就不用验证了，

    $("#form-tag-add").validate({
        focusCleanup: true
    });

    //验证code码
    $("#codeid").blur(function (event) {
        var code = $(event.target).val();
        var rex = /^\d{18}$/;
        console.log(code)

        if (codeB != null && codeB == code)
            $("#codePrompt i:eq(1)").attr("class", "fa fa-check green");
        else if (rex.test(code)) {
            $.post(prefix + "/erify", {code: code + ""}, function (res) {
                console.log(res)
                if (res.code != 200) {
                    $.modal.msgError(res.msg);
                    $("#codePrompt i:eq(1)").attr("class", "fa fa-close red");
                } else {
                    codeB = code;
                    $("#codePrompt i:eq(1)").attr("class", "fa fa-check green");
                }
            })
        } else
            $("#codePrompt i:eq(1)").attr("class", "fa fa-close red");
    })

    $("#stagingId").change(function (event) {
        var stagingId = $(event.target).val();
        //获取当前医院采集员
        //获取采集人员用户集合
        if (stagingId != null) {
            getUser(stagingId);
            getDept(stagingId);
            // getBucket(stagingId);
            // getdep(stagingId);
        }
        console.log('stagingId', stagingId)
    })

    // input 监听
    // $('.selling_cards').on("ifChecked", function () {
    //     console.log(this)
    //     inputType = $(this).val(); //值
    //     if (inputType == 20) {//批量采集
    //         //去掉 科室、来源垃圾桶、科室时间、输入重量方式、照片地址、采集时间、入库垃圾桶、
    //         $("input[name='sourceDeptId']").attr("disabled", true);
    //         // $("input[name='bag']").attr("", "");
    //     } else {
    //     }
    //     console.log('type', inputType)
    // })

    //监听 获取code 码
    $(".fa-mail-forward").on("click", function () {
        var url = ctx + "yf/tag/add/codeid", options = {
            length: 18
        };
        $.operate.post(url, options, function (res) {
            console.log(res)
            if (res.code == 200)
                $("#codeid").val(res.data),
                    $("#codePrompt i:eq(1)").attr("class", "fa fa-check green");
        });
    });


    //获取用户
    function getUser(stagingId) {
        $.post(ctx + "system/user/adds/list", {
            stagingId: stagingId
        }, function (res) {
            if (res.code == 0) {
                console.log(res)
                var html = "<option value='0'>请选择</option>";
                $.each(res.rows, function (i, v) {
                    html += ' <option value="' + v.userId + '" >' + v.userName + '</option>';
                })
                if (html != "") {
                    //采集员
                    $("#collectUserId").html(html)
                    $("#collectUserId").attr("disabled", false);
                    //入库员
                    $("#intoUserId").html(html)
                    $("#intoUserId").attr("disabled", false);
                    //出库员
                    $("#outUserId").html(html)
                    $("#outUserId").attr("disabled", false);
                } else {
                    //采集员
                    $("#collectUserId").html('<option value="" >请选择</option>')
                    $("#collectUserId").attr("disabled", true);
                    //入库员
                    $("#intoUserId").html('<option value="" >请选择</option>')
                    $("#intoUserId").attr("disabled", true);
                    //出库员
                    $("#outUserId").html('<option value="" >请选择</option>')
                    $("#outUserId").attr("disabled", true);
                }
            }
        });
    }


    //获取垃圾桶
    function getBucket(stagingId) {
        $.post(ctx + 'yf/bucket/adds/list', {
            stagingId: stagingId
        }, function (res) {
            if (res.code == 0) {
                console.log(res)
                var html = "";
                $.each(res.rows, function (i, v) {
                    html += ' <option value="' + v.bucketId + '" >' + v.bucketId + '</option>';
                })
                if (html != "") {
                    //采集垃圾桶
                    $("#sourceBucketId").html(html)
                    $("#sourceBucketId").attr("disabled", false);
                    //入库垃圾桶
                    $("#intoBucketId").html(html)
                    $("#intoBucketId").attr("disabled", false);
                    //出库垃圾桶
                    $("#outBucketId").html(html)
                    $("#outBucketId").attr("disabled", false);
                } else {
                    //采集垃圾桶
                    $("#sourceBucketId").html('<option value="" >请选择</option>')
                    $("#sourceBucketId").attr("disabled", true);
                    //入库垃圾桶
                    $("#intoBucketId").html('<option value="" >请选择</option>')
                    $("#intoBucketId").attr("disabled", true);
                    //出库垃圾桶
                    $("#outBucketId").html('<option value="" >请选择</option>')
                    $("#outBucketId").attr("disabled", true);
                }
            }
        });
    }

    //获取科室 ok
    function getDept(stagingId) {
        $.post(ctx + 'yf/dept/adds/list', {
            stagingId: stagingId
        }, function (res) {
            if (res.code == 0) {
                console.log(res)
                var html = "";
                $.each(res.rows, function (i, v) {
                    html += ' <option value="' + v.deptId + '" >' + v.deptName + '</option>';
                })
                if (html != "") {
                    $("select[name='sourceDeptId']").html(html)
                    $("select[name='sourceDeptId']").attr("disabled", false);
                } else {
                    $("select[name='sourceDeptId']").html('<option value="" >暂无科室</option>')
                    $("select[name='sourceDeptId']").attr("disabled", true);
                }
            }
        });
    }

    //获取暂存处
    // function getdep(stagingId) {
    //     $.post(ctx + 'system/dept/adds/list', {
    //         stagingId: stagingId,
    //         grade: 11
    //     }, function (res) {
    //         if (res.code == 0) {
    //             console.log(res)
    //             var html = "";
    //             $.each(res.rows, function (i, v) {
    //                 html += ' <option value="' + v.deptId + '" >' + v.deptName + '</option>';
    //             })
    //             if (html != "") {
    //                 $("#stagingId").html(html)
    //                 $("#stagingId").attr("disabled", false);
    //             } else {
    //                 $("#stagingId").html('<option value="" >请选择</option>')
    //                 $("#stagingId").attr("disabled", true);
    //             }
    //         }
    //     });
    // }


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-tag-add').serialize());
        }
    }

    $("input[name='collectScanDate']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='scanDeptDate']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='collectUpdateDate']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='intoDate']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });

    $("input[name='outDate']").datetimepicker({
        format: "yyyy-mm-dd hh:ii:ss",
        autoclose: true
    });
</script>
</body>
</html>